const { JSDOM } = require("jsdom");

module.exports = getNewsList;

function getNewsList(link) {
  return JSDOM.fromURL(link).then((dom) => {
    let list = [];
    let document = dom.window.document;

    document
      .querySelectorAll(".article-item-wrap[event-track-params]")
      .forEach((el) => {
        let params = JSON.parse(el.getAttribute("event-track-params"));
        if (params && params.customize.video_id === "-1") {
          let url = el.querySelector(".tibt-card__top").href;
          let title = el
            .querySelector(".tibt-card__top img")
            .getAttribute("alt");
          list.push({ title, url });
        }
      });

    return list;
  });
}
